package gemini.castor.ui.client.page.content.office.mystory.form;

import gemini.castor.ui.client.constants.I18nConstants;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.uibinder.client.UiTemplate;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.TextArea;
import com.google.gwt.user.client.ui.Widget;

public class MyStoryFormView extends Composite implements
		MyStoryFormPresenter.Display {

	@UiTemplate("MyStoryFormView.ui.xml")
	interface MyUiBinder extends UiBinder<Panel, MyStoryFormView> {
	}

	private static final MyUiBinder binder = GWT.create(MyUiBinder.class);
	private I18nConstants constants;

	public MyStoryFormView() {
		initWidget(binder.createAndBindUi(this));
		constants = GWT.create(I18nConstants.class);
	}

	@UiField
	TextArea rtaWriteStory;
	
	@UiField
	Button btnSubmit;
	
	@UiField
	HTML htmWriteStory;
	
	@UiField
	TextArea rtaWriteSuccessStory;
	
	@UiField
	Button btnEdit;
	
	@UiField
	HTML htmWriteSuccessStory;

	@Override
	public Widget asWidget() {
		return this;
	}

	@Override
	public void loadData() {
		htmWriteStory.setText("I am Binh, 24 years old. Before, I am 78kgs. After 4 weeks use this product, I lose 8kgs. And I feel my healthy be very good. Thanks Herbalife");
		htmWriteSuccessStory.setText("I am Binh, 24 years old. I feel so tired with my job. But now, with Herbalife, I feel freedom, confident. And I have a good healthy. Thanks Hearbelife");
	}
	
	@UiHandler("btnSubmit")
	void editandsubmit(ClickEvent e){
		if(btnSubmit.getText().contains(constants.btnEdit())){
			rtaWriteStory.setText("I am Binh, 24 years old. Before, I am 78kgs. After 4 weeks use this product, I lose 8kgs. And I feel my healthy be very good. Thanks Herbalife");
			rtaWriteStory.setVisible(true);
			btnSubmit.setText(constants.btnSubmit());
		}else{
			htmWriteStory.setText(rtaWriteStory.getText());
			rtaWriteStory.setVisible(false);
			btnSubmit.setText(constants.btnEdit());
		}
	}
	@UiHandler("btnEdit")
	void editandsubmit2(ClickEvent e){
		if(btnEdit.getText().contains(constants.btnEdit())){
			rtaWriteSuccessStory.setText("I am Binh, 24 years old. I feel so tired with my job. But now, with Herbalife, I feel freedom, confident. And I have a good healthy. Thanks Hearbelife");
			rtaWriteSuccessStory.setVisible(true);
			btnEdit.setText(constants.btnSubmit());
		}else{
			htmWriteSuccessStory.setText(rtaWriteSuccessStory.getText());
			rtaWriteSuccessStory.setVisible(false);
			btnEdit.setText(constants.btnEdit());
		}
	}
}
